<template>
  <el-card class="box-card">
    <el-table :data="page.rows" highlight-current-row stripe border>
      <el-table-column prop="version" label="版本" width="80px"></el-table-column>
      <el-table-column prop="content" label="内容"></el-table-column>
      <el-table-column prop="force" label="强制更新" width="100px"></el-table-column>
      <el-table-column prop="androidUrl" label="Android链接"></el-table-column>
      <el-table-column prop="iosUrl" label="ios链接"></el-table-column>
      <el-table-column label="操作" width="100px">
        <template scope="scope">
            <el-button title="编辑" icon="edit" size="mini" @click="handleEdit(scope.row)"></el-button>
            <el-button title="删除" icon="delete" size="mini" type="danger" @click="handleDelete(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-col :span="24" class="toolPage">
      <el-button @click="handleCreate" type="info" size="normal">添加版本信息</el-button>
      <el-pagination :current-page="page.current" :page-sizes="[10, 20, 50, 100]" :page-size="page.size"
                     layout="total, sizes, prev, pager, next, jumper"
                     :total="page.total" style="float:right"
                     @size-change="handleSizeChange"
                     @current-change="handlePageChange">
      </el-pagination>
    </el-col>
  </el-card>
</template>

<style>

</style>
<script>
import * as Auth from 'common/auth'
export default{
    created(){
      this.load()
    },
    data(){
        return{
            editData:{
              version:'',
              content:'',
              forceUpdate:'',
              force:'',
              androidUrl:'',
              iosUrl:'',
            },
            page: {
              total: 0,
              current: 1,
              size: 10,
              rows: []
            },
             computed: {
                hasAddPermission: () => Auth.hasPermission('admins:add'),
                hasEditPermission: () => Auth.hasPermission('admins:edit')
             }
        }
    },
    methods: {
       handleSizeChange(size) {
        this.page.size = size;
        this.loadGridData();
       },
       handlePageChange(current) {
        this.page.current = current
        this.loadGridData()
       },
       load(){
        let param = {
          pageSize: this.page.size,
          page: this.page.current,
          name: this.user
        }
        this.axios.get("/version_infos", {params: param}).then(response=>{this.page=response.data})
       },
       handleEdit(row){
         this.$router.push(`/version_infos/${row.id}/edit`)
       },
       handleCreate(){
         this.$router.push(`/version_infos/new`)
       },
       handleDelete(row){
         this.$confirm('确认删除此信息吗?', '提示', {
          cancelButtonText: '取消',
          confirmButtonText: '确定',

         }).then(()=>{ this.axios.delete(`/version_infos/${row.id}`).then(()=>{this.load()})
            })
       }
    }
}

</script>
